﻿using System.Collections.Generic;
using System.Web.Routing;

namespace Basmus.Values.Web
{
    public class RouteDataValuesProvider : IValuesProvider<string>
    {
        private readonly RouteData _routeData;

        public RouteDataValuesProvider(RouteData routeData)
        {
            _routeData = routeData;
        }

        public IEnumerable<string> GetNames()
        {
            return _routeData.Values.Keys;
        }

        public IEnumerable<string> GetValues(string name)
        {
            var hasValue = _routeData.Values.ContainsKey(name);
            if (hasValue)
            {
                var result = _routeData.Values[name].ToString().Split(',');
                return result;
            }
            return null;
        }
    }
}